Rust Note
Meow King January 06, 2024 Updated: January 06, 2024 #rust #note #collection-
function accept parameters similar type, like
str,&str,Stringfn accept_all_strings(value: impl AsRef<str>)
just need a string referencefn accept_all_strings(value: impl Into<String>)
need an owned string
-
use
clonedmethod to solve some conversion error in iteration collection.
let results = ;
let result: = results.iter.cloned.collect;
- build a map using
foldandentry
let map: = new;
self.rounds
.iter
.fold
.values
.product
-
Rust built-in traits: see Effective Rust - std-traits.
Additional Note: -
FromStrtrait: str'sparsemethod. -
Ownership
-
into_iteranditerinto_itertakes ownership, whilteiternot. So when origin is something likeVec<String>, theninto_iter->String(Item type), whileiter->&String; When&Vec<String>, theninto_iter->&String, whileiter->&&String -
Useful functions:
-
HashSet:retain